package com.sdhs.paas.sdk.core.logger;

import ch.qos.logback.classic.Level;
import org.slf4j.Marker;

public final class Logger{

    private static final String FQCN = Logger.class.getName();
    private ch.qos.logback.classic.Logger LOGGER = null;

    private Logger(){

    }

    private Logger(String className){
        LOGGER = (ch.qos.logback.classic.Logger)org.slf4j.LoggerFactory.getLogger(className);
    }
    /**
     *
     *
     * @return 获得日志，自动判定日志发出者
     *
     */
    private static ch.qos.logback.classic.Logger innerGet() {
        ch.qos.logback.classic.Logger logBacklogger;
        logBacklogger = (ch.qos.logback.classic.Logger)org.slf4j.LoggerFactory.getLogger(Util.getCallingClass().getName());
        return logBacklogger;

    }

    public void trace(String msg) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.TRACE), msg, null, (Throwable)null);
    }

    public void trace(String format, Object... argArray) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.TRACE), format, argArray, (Throwable)null);
    }

    public void debug(String msg) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.DEBUG), msg, null, (Throwable)null);
    }

    public void debug(String format, Object... argArray) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.DEBUG), format, argArray, (Throwable)null);
    }

    public void info(String msg){
        LOGGER.log(null, FQCN, Level.toLocationAwareLoggerInteger(Level.INFO), msg, null, null);
    }

    public void info(String format, Object... argArray) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.INFO), format, argArray, (Throwable)null);
    }

    public void warn(String msg){
        LOGGER.log(null, FQCN, Level.toLocationAwareLoggerInteger(Level.WARN), msg, null, null);
    }

    public void warn(String format, Object... argArray) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.WARN), format, argArray, (Throwable)null);
    }

    public void error(String msg){
        LOGGER.log(null, FQCN, Level.toLocationAwareLoggerInteger(Level.ERROR), msg, null, null);
    }

    public void error(String format, Object... argArray) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.ERROR), format, argArray, (Throwable)null);
    }

    public void error(String msg, Throwable t) {
        LOGGER.log((Marker)null, FQCN, Level.toLocationAwareLoggerInteger(Level.ERROR), msg, null, t);
    }

    public static class Builder{
        private String className;
        public Builder setClassName(String name){
            this.className = name;
            return this;
        }

        public Logger build(){
            return new Logger(className);
        }

    }
}
